﻿ var files;
        var currentPhoto = 0;
        var navFlag;
        var navOpc = .4;
        $(document).ready(
        function () {
            $("#nextPhoto").click(NextPhoto);
            $("#previosPhoto").click(PreviosPhoto);
            $("#photoContainer").hover(function () { NavBarShow(); });
            $("#photoContainer").mouseover(function () { NavBarShow(); });
            $("#photoContainer").mouseleave(function () { NavBarHide(); });
            $("#nextButtImage").mouseover(function () { NavBarFullShow(); });
            $("#backButtImage").mouseover(function () { NavBarFullShow(); });
            $("#nextButtImage").mouseenter(function () { NavBarFullShow(); });
            $("#backButtImage").mouseenter(function () { NavBarFullShow(); });
            $("#nextButtImage").mouseout(function () { NavBarHalfShow(); });
            $("#backButtImage").mouseout(function () { NavBarHalfShow(); });
            $("#closeButton").click(function () { $("#photoViewer").hide(); });
            $("#photoContainerImage").click(NextPhoto);
            ShowPicture(0);
        }
        );


        function ShowPicture(id) {
            if (isNaN(id)) {
                id = 0;
            }
            var image = $("#photoContainerImage");
            var top = image.height() / 2 + 50;
            $("#photoWait").css("top", top / 2);
            $("#navBar").css("top", -(top - 50));
            $("#photoWait").show();
            $("#photoContainerImage").hide();
            $("#photoContainerImage").load(function () {
                $("#photoWait").hide();
                $("#photoContainerImage").fadeIn("slow");
                image = $("#photoContainerImage");
                var top = image.height() / 2;
                $("#photoContainer").css("height", image.height() + 40);
                $("#photoContainer").css("width", image.width() + 40);
                $("#navBar").css("top", -(top + 20));
                navFlag = true;
                NavBarShow();
            });
           if(files!=undefined)
            var src = "ThumbnailHandler.ashx?imageUrl=" + files[id] + "&ext=jpg" + "&maxH=400" + "&maxW=400";
            $("#photoContainerImage").attr("src", src);

        }

        function NextPhoto() {

            NavBarHide();
            navFlag = false;
            if (currentPhoto < files.length - 1)
                currentPhoto++;
            else
                currentPhoto = 0;
            ShowPicture(currentPhoto);
        }
        function PreviosPhoto() {

            $("#navBar").hide();
            if (currentPhoto > 0)
                currentPhoto--;
            else
                currentPhoto = files.length - 1;
            ShowPicture(currentPhoto);

        }
        function NavBarShow() {
            if (navFlag)
                $("#navBar").fadeTo("fast", navOpc);

        }

        function NavBarHide() {
            $("#navBar").hide();
        }

        function NavBarFullShow() {

            navOpc = 0.8;
        }

        function NavBarHalfShow() {
            navOpc = 0.4;
        }